<?
if ( ! empty ($_POST['connection_token'])) {
  $token = $_POST['connection_token'];  $site_subdomain = $settings["oneall_subdomain"];
  $site_public_key = $settings["site_public_key"];  $site_private_key = $settings["site_private_key"];  $site_domain = $site_subdomain.'.api.oneall.com';
  $resource_uri = 'https://'.$site_domain.'/connections/'.$token .'.json';
  $curl = curl_init();  curl_setopt($curl, CURLOPT_URL, $resource_uri);  curl_setopt($curl, CURLOPT_HEADER, 0);
  curl_setopt($curl, CURLOPT_USERPWD, $site_public_key . ":" . $site_private_key);
  curl_setopt($curl, CURLOPT_TIMEOUT, 15);  curl_setopt($curl, CURLOPT_VERBOSE, 0);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
  curl_setopt($curl, CURLOPT_FAILONERROR, 0);  $result_json = curl_exec($curl);
  curl_close($curl);  $json = json_decode ($result_json);
    switch($json->response->result->data->user->identity->provider) {
				case 'twitter':
					$name1 = $json->response->result->data->user->identity->displayName;
					$name2 = "@".$json->response->result->data->user->identity->preferredUsername;
					$pic = $json->response->result->data->user->identity->thumbnailUrl;
					$email = "";
					break;
				case 'google':
					$name2 = $json->response->result->data->user->identity->emails[0]->value;
					$name1 = $json->response->result->data->user->identity->displayName;
					$pic = 'http://' . $_SERVER['SERVER_NAME'] . str_replace($_SERVER['DOCUMENT_ROOT'],'',dirname(__FILE__)) . '/google+.png';
					$email = $name2;
					break;
			   case 'facebook':
					$name2 = $json->response->result->data->user->identity->emails[0]->value;
					$name1 = $json->response->result->data->user->identity->displayName;
					$pic = $json->response->result->data->user->identity->thumbnailUrl;
					$email = $name2;
					break;		
			   case 'linkedin':	
					$name1 = trim($json->response->result->data->user->identity->displayName);
					$pic = 'http://' . $_SERVER['SERVER_NAME'] . str_replace($_SERVER['DOCUMENT_ROOT'],'',dirname(__FILE__)) . '/linkedin.jpg';
					$name2 = $email = "";
					break;		
			   case 'windowslive':	
				   $name2 = $json->response->result->data->user->identity->emails[0]->value;
					$name1 = $json->response->result->data->user->identity->displayName;
					$pic = 'http://' . $_SERVER['SERVER_NAME'] . str_replace($_SERVER['DOCUMENT_ROOT'],'',dirname(__FILE__)) . '/winlive.jpg';
					$email = $name2;		
					break;
			   default:	
				   $name2 = $json->response->result->data->user->identity->emails[0]->value;
					$name1 = $json->response->result->data->user->identity->displayName;
					$pic = $json->response->result->data->user->identity->thumbnailUrl;
					$email = $name2;
	}
			$_SESSION["name1"] = $name1;
			$_SESSION["name2"] = $name2;
			$_SESSION["pic"] = $pic;
			$_SESSION["email"] = $email;
}
?>